package net.xxcxcxcx.xc_enhancedmob.register;

import net.xxcxcxcx.xc_enhancedmob.config.ConfigLoader;
import net.xxcxcxcx.xc_enhancedmob.config.CustomConfig;
import net.xxcxcxcx.xc_enhancedmob.config.TestConfig;
import net.xxcxcxcx.xc_enhancedmob.config.render.RenderConfig;
import net.xxcxcxcx.xc_enhancedmob.config.skill.SkillsConfig;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import static net.xxcxcxcx.xc_enhancedmob.EnhancedMobMod.StartTest;

public class ConfigRegister {
    public static List<CustomConfig> configList = new ArrayList<>();
    public static List<ConfigLoader> configLoaderList = new ArrayList<>();

    public static void Init() {
        if (StartTest) configList.add(new TestConfig());
        configList.add(new RenderConfig());
        configList.add(new SkillsConfig());
        for (int i = 0; i < configList.size(); i++) {
            try {
                ConfigLoader configLoader = new ConfigLoader<>(configList.get(i), config -> {
                    for (int j = 0; j < configList.size(); j++) {
                        if (Objects.equals(configList.get(j).getName(), config.getName())) {
                            configList.set(j, config);
                        }
                    }
                });
                configLoaderList.add(configLoader);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static CustomConfig getConfig(String name) {
        for (CustomConfig customConfig : configList) {
            if (customConfig.getName().equals(name)) {
                return customConfig;
            }
        }
        return null;
    }
}
